package bit.springprinciple.demos;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/dog")
public class DogController {
    @Autowired
    ApplicationContext context;

    @Autowired
    private Dog singleDog;

    @Autowired
    private Dog prototypeDog;

    @Autowired
    private Dog requestDog;

    @Autowired
    private Dog sessionDog;

    @Autowired
    private Dog applicationDog;


    @RequestMapping("/single")
    public String single(){
        Dog contextdog=(Dog)context.getBean("singleDog");
        return "dog:"+singleDog.toString()+"    ,contextdog:"+contextdog;
    }

    @RequestMapping("/prototype")
    public String prototype(){
        Dog contextdog=(Dog)context.getBean("prototypeDog");
        return "dog:"+prototypeDog.toString()+"    ,contextdog:"+contextdog;
    }

    @RequestMapping("/request")
    public String request(){
        Dog contextdog=(Dog)context.getBean("requestDog");
        return "dog:"+requestDog.toString()+"    ,contextdog:"+contextdog;
    }

    @RequestMapping("/session")
    public String session(){
        Dog contextdog=(Dog)context.getBean("sessionDog");
        return "dog:"+sessionDog.toString()+"    ,contextdog:"+contextdog;
    }

    @RequestMapping("/application")
    public String application(){
        Dog contextdog=(Dog)context.getBean("applicationDog");
        return "dog:"+applicationDog.toString()+"    ,contextdog:"+contextdog;
    }
}
